/**
 * @param {number[][]} grid
 * @return {number[][]}
 */
var largestLocal = function (grid) {
  let len = grid.length
  let res = new Array(len - 2).fill(0).map(() => new Array(len - 2).fill(0))
  for (let i = 0; i < len - 2; i++) {
    for(let j=0;j<len-2;j++){
      let a = grid.slice(i,i+3).map(item=>item.slice(i,j+3))
      res[i][j] = Math.max(...grid.slice(i,i+3).map(item=>item.slice(j,j+3)).flat())
    }
  }

  return res
}

largestLocal([[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]])

// let grid=[[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]
// console.log(Math.max(9,9,8));
// console.log(...grid.slice(0,3).map(item=>item.slice(0,3)).flat());
